<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>修改密码 - 光年(Light Year Admin)后台管理系统模板</title>
<link rel="icon" href="/static/images/favicon.ico" type="image/ico">
<meta name="keywords" content="LightYear,光年,后台模板,后台管理系统,光年HTML模板">
<meta name="description" content="LightYear是一个基于Bootstrap v3.3.7的后台管理系统的HTML模板。">
<meta name="author" content="yinqi">
<link href="/static/css/bootstrap.min.css" rel="stylesheet">
<link href="/static/css/materialdesignicons.min.css" rel="stylesheet">
<link href="/static/css/style.min.css" rel="stylesheet">
</head>
  
<body>
<div class="container-fluid p-t-15">
  
  <div class="row">
    <div class="col-lg-12">
      <div class="card">
        <div class="card-body">
          
          <form method="post" class="site-form">
            <div class="form-group">
              <label for="old-password">旧密码</label>
              <input type="password" class="form-control" id="old-password" placeholder="输入账号的原登录密码">
              <span class="help-block"></span>
            </div>
            <div class="form-group">
              <label for="new-password">新密码</label>
              <input type="password" class="form-control" id="new-password" placeholder="输入新的密码">
              <span class="help-block"></span>
            </div>
            <div class="form-group">
              <label for="confirm-password">确认新密码</label>
              <input type="password" class="form-control" id="confirm-password" placeholder="请再次输入密码">
              <span class="help-block"></span>
            </div>
            <button type="submit" class="btn btn-primary" id="submit_btn">修改密码</button>
          </form>
 
        </div>
      </div>
    </div>
    
  </div>
  
</div>

<script type="text/javascript" src="/static/js/jquery.min.js"></script>
<script type="text/javascript" src="/static/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/static/js/main.min.js"></script>
<script src="/static/js/bootstrap-notify.min.js"></script>
<script type="text/javascript" src="/static/js/lightyear.js"></script>
<script src="/static/js/mycommons.js"></script>
<script>
  $("#submit_btn").click(function (e) {
    let oldPwd = $.trim($("#old-password").val())
    let newPwd = $.trim($("#new-password").val())
    let confirmPwd = $.trim($("#confirm-password").val())

    if (oldPwd.length === 0 || oldPwd === "") {
      show_verify_info('#old-password', 'error', '请输入原密码')
      return false
    } else {
      show_verify_info('#old-password', 'success', '')
    }

    if (newPwd.length !==0 && newPwd !== '' && /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,14}$/.test(newPwd)) {
      show_verify_info('#new-password', 'success', '')
    } else {
      show_verify_info('#new-password', 'error', '密码必须包含大小写字母和数字，可以使用特殊字符，长度在 8-14之间')
      return false
    }

    if (confirmPwd !== newPwd) {
      show_verify_info('#confirm-password', 'error', '确认密码与新密码不一致')
      return false
    } else {
      show_verify_info('#confirm-password', 'success', '')
    }

    e.preventDefault()
    $.ajax({
      url: "/editPwd",
      type: 'PUT',
      data: {oldPwd: oldPwd, newPwd: newPwd},
      success(res) {
        if (res.flag) {
          msgNotify(res.msg, 'success', 1500)
          setTimeout(function () {
            parent.location.href = "/loginPage"
          }, 1500)
        } else {
          msgNotify(res.msg, 'danger', 1500)
        }
      }
    })

  })

  /*
  显示校验信息
   */
  function show_verify_info(item, status, msg) {
    $(item).parent().removeClass("has-success has-error")
    if ("success" === status) {
      $(item).parent().addClass("has-success")
      $(item).next("span").text("")
    } else if ("error" === status) {
      $(item).parent().addClass("has-error")
      $(item).next("span").text(msg)
    }
  }
</script>
</body>
</html>